/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vec;

/**
 *
 * @author Vic
 */
public class Vector3f implements Cloneable {

    public float x, y, z;

    public float dot(Vector3f vec) {
        return this.x * vec.x + this.y * vec.y + this.z * vec.z;
    }

    public Vector3f add(Vector3f arg) {
        this.x += arg.x;
        this.y += arg.y;
        this.z += arg.z;
        return this;
    }

    public Vector3f sub(Vector3f arg) {
        this.x -= arg.x;
        this.y -= arg.y;
        this.z -= arg.z;
        return this;
    }

    public Vector3f mul(Vector3f arg) {
        this.x *= arg.x;
        this.y *= arg.y;
        this.z *= arg.z;
        return this;
    }

    public Vector3f div(Vector3f arg) {
        this.x /= arg.x;
        this.y /= arg.y;
        this.z /= arg.z;
        return this;
    }

    public Vector3f scale(float scale) {
        this.x *= scale;
        this.y *= scale;
        this.z *= scale;
        return this;
    }

    public Vector3f cross(Vector3f vec) {
        float x, y, z;
        x = this.z * vec.y - this.y * vec.z;
        y = this.z * vec.x - this.x * vec.z;
        z = this.x * vec.y - this.y * vec.x;
        this.x = x;
        this.y = y;
        this.z = z;
        return this;
    }

    public Vector3f() {
        super();
    }

    public Vector3f(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Vector3f(Vector3f tup) {
        this.x = tup.x;
        this.y = tup.y;
        this.z = tup.z;
    }

    @Override
    public Object clone() {
        return new Vector3f(this);
    }

    public float length() {
        return (float) Math.sqrt(this.dot(this));
    }

    public void normalize() {
        this.scale(1 / this.length());
    }

    public void clear() {
        x = y = z = 0;
    }

    @Override
    public String toString() {
        return "<" + x + "," + y + "," + z + ">";
    }
}
